package org.mspring.mlog.service.impl;

import java.util.List;

import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.mspring.mlog.entity.TwitterReply;
import org.mspring.mlog.service.TwitterReplyService;
import org.mspring.platform.dao.hibernate.GenericDao;
import org.mspring.platform.dao.hibernate.common.EnhancedRule;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月19日
 */
@Service
@Transactional
public class TwitterReplyServiceImpl extends GenericDao<TwitterReply, Long> implements TwitterReplyService {

    @Override
    public List<TwitterReply> getTwitterReplyList(Long twitter, int num) {
        // TODO Auto-generated method stub
        EnhancedRule rule = new EnhancedRule();
        rule.setPageSize(num);
        rule.add(Restrictions.eq("twitter.id", twitter));
        rule.addOrder(Order.desc("id"));
        return list(rule);
    }

    @Override
    public void deleteReply(Long twitter) {
        // TODO Auto-generated method stub
        if (twitter == null) {
            return;
        }
        executeUpdate("delete from TwitterReply r where r.twitter.id = ?", twitter);
    }

}
